import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javax.swing.*;

/**
 * Template_Window
 * JFrame where the user choose which image he or she wishes to work with.
 */
public class Template_Window extends JFrame{
	public ImageIcon img;
	public JPanel top_JPanel;
	private JPanel jContentPane = null;
	
	public Template_Window(Window_Controller wc) {
		super();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		initialize(wc);
	}
	
	/**
	 * Setup of the JFrame
	 * @param wc
	 */
	private void initialize(Window_Controller wc) {
		//this.setSize(600,600);
		this.setContentPane(getJContentPane(wc));
		this.setTitle("Vil du lave en film ud af dette billede?");
		this.setLocationRelativeTo(null);
		this.setVisible(false);
		this.setResizable(false);
	}
	
	/**
	 * Sets the frame width to a minimum of 600 pixels 
	 * @param width
	 * @param height
	 */
	public void setFrameSize(int width, int height) {
		if (width < 600) {
			this.setSize(600,height + 250);	
		} else {
			this.setSize(width,height + 250);
		}
	}
	
	/**
	 * Setup of the panel
	 * @param wc
	 * @return
	 */
	private JPanel getJContentPane(Window_Controller wc) {
		if(jContentPane == null) {
			final Window_Controller wcon = wc;
			
			Insets noInsets=new Insets(0,0,0,0);
			
			img = new ImageIcon(ImageDB.images.get("default"));
			
			setFrameSize(img.getIconWidth(),img.getIconHeight());
			
			top_JPanel = new JPanel();
			JPanel bottom_JPanel = new JPanel();
			JLabel top_JLabel = new JLabel("Vil du lave en film ud af dette billede?"), jLabel2 = new JLabel(img);
			JButton yes_JButton = new JButton(new ImageIcon(ImageDB.images.get("tut_button_yesImg"))),
					no_JButton = new JButton(new ImageIcon(ImageDB.images.get("tut_button_noImg")));
			
			top_JLabel.setFont((new Font("Comic Sans MS",Font.PLAIN,27)));
			jLabel2.setPreferredSize(new Dimension(img.getIconWidth(),img.getIconHeight()));
			
			yes_JButton.setMargin(noInsets);			
			yes_JButton.setBorder(BorderFactory.createEmptyBorder());
			yes_JButton.setContentAreaFilled(false);
			yes_JButton.addActionListener(new ActionListener(){
				  public void actionPerformed(ActionEvent e){
					  wcon.hide_Template_Window();
					  wcon.show_Mark_Window(img);
				  }
			});
			
			no_JButton.setMargin(noInsets);			
			no_JButton.setBorder(BorderFactory.createEmptyBorder());
			no_JButton.setContentAreaFilled(false);
			no_JButton.addActionListener(new ActionListener(){
				  public void actionPerformed(ActionEvent e){
					  wcon.show_FileChooser();
					  //dispose();
				  }
			});
			
			top_JPanel.setLayout(new BorderLayout());
			top_JPanel.setBackground(Color.WHITE);
			top_JPanel.add(top_JLabel, BorderLayout.NORTH);
			top_JPanel.add(jLabel2, BorderLayout.CENTER);
			
			bottom_JPanel.setLayout(new FlowLayout());
			bottom_JPanel.setBackground(Color.WHITE);
			bottom_JPanel.add(yes_JButton);
			bottom_JPanel.add(no_JButton);
			
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setBackground(Color.WHITE);
			jContentPane.add(top_JPanel, BorderLayout.NORTH);
			jContentPane.add(bottom_JPanel);
		}
		return jContentPane;
	}
}
